package cn.chencaiju.algorithm;

public class PlantFlowers {
	public static void main(String[] args) {
		int[] flowerbed= {0};
		System.out.println(canPlaceFlowers(flowerbed,1));
	}
	public static boolean canPlaceFlowers(int[] flowerbed, int n) {
		int end=flowerbed.length;
		if(n==0)return true;
		if(end<2&&n==1&&flowerbed[0]==0)return true;
		int count=0;
		if(end>1&&flowerbed[0]==0&&flowerbed[1]==0) {
			count++;
			flowerbed[0]=1;
		}
		if(end>1&&flowerbed[end-1]==0&&flowerbed[end-2]==0) {
			count++;
			flowerbed[end-1]=1;
		}
		for(int i=1;i<end-2;) {
			if(flowerbed[i]!=0) {
				i+=1;
				continue;
			}
			if(flowerbed[i+1]!=0) {
				i+=2;
				continue;
			}
			if(flowerbed[i+2]==0) {
				count++;
				i+=2;
				continue;
			}
			i+=3;						
		}
		return count>=n;
	}
}
